package com.wyzz.hr.action;

import java.util.Map;
import org.apache.commons.lang.StringUtils;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.util.DatabaseSysConfigManager;
import com.wyzz.hr.util.SysConfigManager;

public class ConfigExamin extends BaseAction {
	public ConfigExamin() {
		dbConfigManager = DatabaseSysConfigManager.getInstance();
	}

	public String showConfigExamin() throws Exception {
		Map dbMap = dbConfigManager.getProperties();
		sys_examin_create_level = StringUtils.defaultIfEmpty((String) dbMap
				.get("sys.examin.create.level"), "1");
		sys_examin_update_level = StringUtils.defaultIfEmpty((String) dbMap
				.get("sys.examin.update.level"), "1");
		sys_examin_lr_confirm = StringUtils.defaultIfEmpty((String) dbMap
				.get("sys.examin.lr.confirm"), "0");
		sys_examin_ot_confirm = StringUtils.defaultIfEmpty((String) dbMap
				.get("sys.examin.ot.confirm"), "0");
		sys_examin_shift_enable = StringUtils.defaultIfEmpty((String) dbMap
				.get("sys.examin.shift.enable"), "0");
		sys_examin_shiftimport_override = StringUtils.defaultIfEmpty(
				(String) dbMap.get("sys.examin.shiftimport.override"), "0");
		sys_examin_leave_type = StringUtils.defaultIfEmpty((String) dbMap
				.get("sys.examin.leave.type"), "0");
		sys_examin_tiaoxiu_match = StringUtils.defaultIfEmpty((String) dbMap
				.get("sys.examin.tiaoxiu.match"), "0");
		sys_examin_ot_match = StringUtils.defaultIfEmpty((String) dbMap
				.get("sys.examin.ot.match"), "0");
		sys_examin_ot_tiaoxiu = StringUtils.defaultIfEmpty((String) dbMap
				.get("sys.examin.ot.tiaoxiu"), "0");
		String sys_examin_month_sum = StringUtils.defaultIfEmpty((String) dbMap
				.get("sys.examin.month.sum"), "1-1");
		if (!sys_examin_month_sum.matches("\\d+-\\d+"))
			sys_examin_month_sum = "1-1";
		String strs[] = sys_examin_month_sum.split("-");
		beginMonth = Integer.valueOf(Integer.parseInt(strs[0]));
		beginDay = strs[1];
		return "success";
	}

	public String executeExamin() throws Exception {
		Map dbMap = dbConfigManager.getProperties();
		if (!((String) dbMap.get("sys.examin.create.level"))
				.equals(sys_examin_create_level))
			dbConfigManager.setProperty("sys.examin.create.level",
					sys_examin_create_level);
		if (!((String) dbMap.get("sys.examin.update.level"))
				.equals(sys_examin_update_level))
			dbConfigManager.setProperty("sys.examin.update.level",
					sys_examin_update_level);
		if (!((String) dbMap.get("sys.examin.lr.confirm"))
				.equals(sys_examin_lr_confirm))
			dbConfigManager.setProperty("sys.examin.lr.confirm",
					sys_examin_lr_confirm);
		if (!((String) dbMap.get("sys.examin.ot.confirm"))
				.equals(sys_examin_ot_confirm))
			dbConfigManager.setProperty("sys.examin.ot.confirm",
					sys_examin_ot_confirm);
		String sys_examin_month_sum = (new StringBuilder()).append(
				Integer.toString(beginMonth.intValue())).append("-").append(
				beginDay).toString();
		if (!((String) dbMap.get("sys.examin.month.sum"))
				.equals(sys_examin_month_sum))
			dbConfigManager.setProperty("sys.examin.month.sum",
					sys_examin_month_sum);
		if (!((String) dbMap.get("sys.examin.shift.enable"))
				.equals(sys_examin_shift_enable))
			dbConfigManager.setProperty("sys.examin.shift.enable",
					sys_examin_shift_enable);
		if (!((String) dbMap.get("sys.examin.shiftimport.override"))
				.equals(sys_examin_shiftimport_override))
			dbConfigManager.setProperty("sys.examin.shiftimport.override",
					sys_examin_shiftimport_override);
		if (!((String) dbMap.get("sys.examin.leave.type"))
				.equals(sys_examin_leave_type))
			dbConfigManager.setProperty("sys.examin.leave.type",
					sys_examin_leave_type);
		if (!((String) dbMap.get("sys.examin.ot.tiaoxiu"))
				.equals(sys_examin_ot_tiaoxiu))
			dbConfigManager.setProperty("sys.examin.ot.tiaoxiu",
					sys_examin_ot_tiaoxiu);
		if (!((String) dbMap.get("sys.examin.tiaoxiu.match"))
				.equals(sys_examin_tiaoxiu_match))
			dbConfigManager.setProperty("sys.examin.tiaoxiu.match",
					sys_examin_tiaoxiu_match);
		if (!((String) dbMap.get("sys.examin.ot.match"))
				.equals(sys_examin_ot_match))
			dbConfigManager.setProperty("sys.examin.ot.match",
					sys_examin_ot_match);
		addSuccessInfo("\u8003\u52E4\u6A21\u5757\u53C2\u6570\u8C03\u6574\u6210\u529F\uFF01");
		return "success";
	}

	public String getSys_examin_create_level() {
		return sys_examin_create_level;
	}

	public void setSys_examin_create_level(String sys_examin_create_level) {
		this.sys_examin_create_level = sys_examin_create_level;
	}

	public String getSys_examin_update_level() {
		return sys_examin_update_level;
	}

	public void setSys_examin_update_level(String sys_examin_update_level) {
		this.sys_examin_update_level = sys_examin_update_level;
	}

	public String getSys_examin_lr_confirm() {
		return sys_examin_lr_confirm;
	}

	public void setSys_examin_lr_confirm(String sys_examin_lr_confirm) {
		this.sys_examin_lr_confirm = sys_examin_lr_confirm;
	}

	public String getSys_examin_ot_confirm() {
		return sys_examin_ot_confirm;
	}

	public void setSys_examin_ot_confirm(String sys_examin_ot_confirm) {
		this.sys_examin_ot_confirm = sys_examin_ot_confirm;
	}

	public Integer getBeginMonth() {
		return beginMonth;
	}

	public void setBeginMonth(Integer beginMonth) {
		this.beginMonth = beginMonth;
	}

	public String getBeginDay() {
		return beginDay;
	}

	public void setBeginDay(String beginDay) {
		this.beginDay = beginDay;
	}

	public String getSys_examin_shift_enable() {
		return sys_examin_shift_enable;
	}

	public void setSys_examin_shift_enable(String sys_examin_shift_enable) {
		this.sys_examin_shift_enable = sys_examin_shift_enable;
	}

	public String getSys_examin_shiftimport_override() {
		return sys_examin_shiftimport_override;
	}

	public void setSys_examin_shiftimport_override(
			String sys_examin_shiftimport_override) {
		this.sys_examin_shiftimport_override = sys_examin_shiftimport_override;
	}

	public String getSys_examin_leave_type() {
		return sys_examin_leave_type;
	}

	public void setSys_examin_leave_type(String sys_examin_leave_type) {
		this.sys_examin_leave_type = sys_examin_leave_type;
	}

	public String getSys_examin_tiaoxiu_match() {
		return sys_examin_tiaoxiu_match;
	}

	public void setSys_examin_tiaoxiu_match(String sys_examin_tiaoxiu_match) {
		this.sys_examin_tiaoxiu_match = sys_examin_tiaoxiu_match;
	}

	public String getSys_examin_ot_match() {
		return sys_examin_ot_match;
	}

	public void setSys_examin_ot_match(String sys_examin_ot_match) {
		this.sys_examin_ot_match = sys_examin_ot_match;
	}

	public String getSys_examin_ot_tiaoxiu() {
		return sys_examin_ot_tiaoxiu;
	}

	public void setSys_examin_ot_tiaoxiu(String sys_examin_ot_tiaoxiu) {
		this.sys_examin_ot_tiaoxiu = sys_examin_ot_tiaoxiu;
	}

	private static final long serialVersionUID = 1L;
	public static final String SUCC = "SUCC";
	public static final String FAIL = "FAIL";
	private String sys_examin_create_level;
	private String sys_examin_update_level;
	private String sys_examin_lr_confirm;
	private String sys_examin_ot_confirm;
	private Integer beginMonth;
	private String beginDay;
	private String sys_examin_shift_enable;
	private String sys_examin_shiftimport_override;
	private String sys_examin_leave_type;
	private String sys_examin_tiaoxiu_match;
	private String sys_examin_ot_match;
	private String sys_examin_ot_tiaoxiu;
	private SysConfigManager dbConfigManager;
}
